home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / mandel.arc / MANDIMG.C < prev    next >
Text File  |  1987-03-11  |  7KB  |  184 lines

  1. /****************************************************************************/
  2. /* MODULE NAME:                                 */
  3. /*    MANDMAKE - Nmemonic "compute MANDelbrot set and MAKE an image file"   */
  4. /*                                        */
  5. /* MODULE DESCRIPTION:                                */
  6. /*    Computes an image file for a given area with a specified magnification*/
  7. /*                                        */
  8. /* USAGE:                                    */
  9. /*    mandel begin_c_real begin_c_imag Xdots Ydots Range Output_file_name   */
  10. /*                                        */
  11. /* INPUT:                                    */
  12. /*    double  A_begin    The real portion of the beginning complex coordinate*/
  13. /*    double  B_begin    The imaginary portion of the beginning coordinate   */
  14. /*    int     Xdots    The number of pixles of the desplay device in X.    */
  15. /*    int     Ydots    The number of pixles of the desplay device in Y.    */
  16. /*    int     Range    The zoom factor to use for the display.         */
  17. /*    FILE    Out_fl_nm The file that will contain the itteration data.     */
  18. /*                                        */
  19. /* OUTPUT:                                    */
  20. /*   An image file.                                */
  21. /*                                        */
  22. /****************************************************************************/
  23.  
  24. /*---> Standard definitions and declares <---*/
  25. #include <stdio.h>
  26. #include <dos.h>
  27.  
  28. /*---> Initialize global constants <---*/
  29. #define then
  30. #define begin {
  31. #define end }
  32. #define TRUE 1
  33. #define FALSE 0
  34. extern    double atof() ;
  35. extern    double sqrt() ;
  36.  
  37. /*---> Define Structures <---*/
  38. struct RHEADER begin        /**********************************************/
  39.    char      NAME[30] ; /* Image name.                  */
  40.    unsigned int  PIX_HT   ; /* Image height in pixles              */
  41.    unsigned int  PIX_WDT  ; /* Image width in pixles.              */
  42.    unsigned int  DAT_WDT  ; /* Data width in bytes.              */
  43.    unsigned int  PIX_SIZ  ; /* Size of pixle in bits.              */
  44.    unsigned int  PIX_FRM  ; /* Pixle format ( ie. b&w, gray, color, etc ) */
  45.    unsigned int  COL_SET  ; /* Color Set ( ie. none, RBG, CMW, etc. )      */
  46.    unsigned int  CMP_FMT  ; /* Compression Format  ( none, blk supress,..)*/
  47.    end ; /*rheader*/        /**********************************************/
  48.  
  49. main( ARGC, ARGV )
  50.  
  51.    /*---> Define Parameters <---*/
  52.    int             ARGC         ; /*                   */
  53.    char         *ARGV[]         ; /*                   */
  54.  
  55. begin    /*MANDEL*/
  56.  
  57.    /*---> Define Local Variables <---*/
  58.    int             ITTER     = 1000; /* Maximum number of itterations/pel*/
  59.  
  60.    FILE         *fp        =  0  ; /* Output image file           */
  61.    struct RHEADER    HEADER         ; /* Header record for new image file */
  62.    int             INDX      =  0  ; /* General purpose counter.       */
  63.    int             INDY      =  0  ; /* General purpose counter.       */
  64.    int             INDZ      =  0  ; /* General purpose counter.       */
  65.    int             XDOTS     =  0  ; /* Number of display pixles in X    */
  66.    int             YDOTS     =  0  ; /* Number of display pixles in Y    */
  67.    int             RET_CODE  =  0  ; /* General purpose return code.       */
  68.    double         XINC      = 0.0 ; /* Distance between pixles       */
  69.    double         YINC      = 0.0 ; /* Distance between pixles       */
  70.    double         A_BEGIN   = 0.0 ; /* Beginning coordinate. Real.       */
  71.    double         B_BEGIN   = 0.0 ; /* Beginning coordinate. Imaginary. */
  72.    double         RANGE     = 0.0 ; /* Zoom factor               */
  73.    double         CA        = 0.0 ; /* Current coordinate. Real.       */
  74.    double         CB        = 0.0 ; /* Current coordinate. Imaginary.   */
  75.    double         ZA        = 0.0 ; /* Current itteration. Real.       */
  76.    double         ZB        = 0.0 ; /* Current itteration. Imaginary.   */
  77.    double         ZSIZE     = 0.0 ; /* Real distance of Z(A,B) from 0,0 */
  78.    double         ZNEWA     = 0.0 ; /* Next itteration. Real.       */
  79.    double         ZNEWB     = 0.0 ; /* Next itteration. Immaginary.       */
  80.  
  81.    /*---> Process runtime arguments <---*/
  82.    if( ARGC < 7 ) then begin
  83.       printf( "INVALID ARGUMENT COUNT of %d . . . . . .\n", ARGC ) ;
  84.       printf( "Use :\n" ) ;
  85.       printf( "mandimg X_real Y_imag  Xdots  Ydots  Range    Out_file\n\n");
  86.  
  87.       printf( "  e.g.  -2.000  -1.250   320   200    2.500   mandata.tmp\n" ) ;
  88.       printf( "        -1.500  -0.500   320   200    0.500   mandata.tmp\n" ) ;
  89.       printf( "        -1.250  -0.200   320   200    0.100   mandata.tmp\n" ) ;
  90.       printf( "        -1.250  -0.180   320   200    0.030   mandata.tmp\n" ) ;
  91.       printf( "        -1.235  -0.171   320   200    0.006   mandata.tmp\n" ) ;
  92.       printf( "        -1.233  -0.169   320   200    0.001   mandata.tmp\n" ) ;
  93.       printf( "        -1.233  -0.169   320   200    0.0001  mandata.tmp\n" ) ;
  94.       printf( "        -1.233  -0.169   320   200    0.00001 mandata.tmp\n" ) ;
  95.       return ;
  96.       end   /*if*/
  97.    A_BEGIN =  atof( ARGV[ 2 ] ) ;
  98.    B_BEGIN =  atof( ARGV[ 1 ] ) ;
  99.    XDOTS   =  atoi( ARGV[ 3 ] ) ;
  100.    YDOTS   =  atoi( ARGV[ 4 ] ) ;
  101.    RANGE   =  atof( ARGV[ 5 ] ) ;
  102.  
  103.    /*---> Open output file <---*/
  104.    fp = fopen( ARGV[6], "w" ) ;
  105.    if( fp == 0 ) then begin
  106.       printf("Open ERROR on output file  : %s \n", ARGV[6] ) ;
  107.       return ;
  108.       end   /*if*/
  109.  
  110.    /*---> Setup image header <---*/
  111.    strcpy( HEADER.NAME, "                             " ) ;
  112.    sprintf( HEADER.NAME, "MB (%8.4f,%8.4f) %7.5f", B_BEGIN, A_BEGIN, RANGE ) ;
  113.    HEADER.PIX_HT   = YDOTS ;
  114.    HEADER.PIX_WDT  = XDOTS ;
  115.    HEADER.DAT_WDT  = XDOTS ;
  116.    HEADER.PIX_SIZ  = 8       ;
  117.    HEADER.PIX_FRM  = 0       ;
  118.    HEADER.COL_SET  = 0       ;
  119.    HEADER.CMP_FMT  = 0       ;
  120.  
  121.    /*---> Output image header <---*/
  122.    fwrite( &HEADER, 1, 44, fp ) ;
  123.  
  124.    /*---> Report new header information <---*/
  125.    printf( "The header is as follows : \n" ) ;
  126.    printf( "   Name       : %s\n", HEADER.NAME     ) ;
  127.    printf( "   Pixle Ht.  : %u\n", HEADER.PIX_HT   ) ;
  128.    printf( "   Pixle Wdt. : %u\n", HEADER.PIX_WDT  ) ;
  129.    printf( "   Data  Wdt. : %u\n", HEADER.DAT_WDT  ) ;
  130.    printf( "   Pixle size : %u\n", HEADER.PIX_SIZ  ) ;
  131.    printf( "   Pixle Fmt. : %u\n", HEADER.PIX_FRM  ) ;
  132.    printf( "   Color Set  : %u\n", HEADER.COL_SET  ) ;
  133.    printf( "   Comp. Fmt. : %u\n", HEADER.CMP_FMT  ) ;
  134.    printf( "Beginning creation of image file . . . . \n" ) ;
  135.  
  136.    /*---> Compute complex spacing between pixles <---*/
  137.    XINC = RANGE / (float)XDOTS ;
  138.    YINC = RANGE / (float)YDOTS ;
  139.  
  140.    /*---> Loop to compute each pixle column value on 2-D Complex grid <---*/
  141.    for( INDY=0; INDY < YDOTS; INDY++ ) begin
  142.  
  143.       /*---> Initialize for new row <---*/
  144.       CA = YINC * INDY + B_BEGIN ;
  145.  
  146.       for( INDX=0; INDX < XDOTS; INDX++ ) begin
  147.  
  148.      /*---> Initialize for new column ( and pixle ) <---*/
  149.      ZA = 0.0 ;
  150.      ZB = 0.0 ;
  151.      CB = XINC * INDX + A_BEGIN ;
  152.      ZSIZE = sqrt(    CA*CA + CB*CB ) ;
  153.  
  154.  
  155.      /*---> Loop to itterate for each ( Z**2 + C ) <---*/
  156.      for( INDZ=0; (ZSIZE < 2) && (INDZ <= ITTER); INDZ++ ) begin
  157.         ZNEWA = ( ZA*ZA ) - ( ZB*ZB ) + CA ;
  158.         ZNEWB = ( 2*ZA*ZB ) + CB ;
  159.         ZSIZE = sqrt( ZNEWA*ZNEWA + ZNEWB*ZNEWB ) ;
  160.         ZA      = ZNEWA ;
  161.         ZB      = ZNEWB ;
  162.         end   /* for INDZ */
  163.  
  164.      /*---> Output results <---*/
  165.      putc( (char)(INDZ / 4), fp ) ;
  166.  
  167.      end   /*for INDX*/
  168.  
  169.       /*---> Check for user requested exit. <---*/
  170.       RET_CODE = kbhit() ;
  171.       if( RET_CODE ) then begin
  172.      INDX = XDOTS ;
  173.      INDY = YDOTS ;
  174.      end   /*if*/
  175.  
  176.       /*---> Report progress to user. <---*/
  177.       printf("Processing for line %d is complete\n", INDY ) ;
  178.  
  179.       end   /*for INDY*/
  180.  
  181.    /*---> Exit <---*/
  182.    return ;
  183.    end     /* MANDEL */
  184.